﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business;
using Entities;

namespace eProjectRailWayReservation.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.RemoveAll();
            txtUsername.Focus();
         
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            
            string emp_ID = string.Empty;
            if (!Business.EmployeeBUS.IsExitEmployee(txtUsername.Text.Trim(), CryptorEngine.Encrypt(txtPassword.Text.Trim(), true), ref emp_ID))
            {
                lblError.Text = "User Name or Password Not Correct.";
            }
            else
            {
                Employee emp = Business.EmployeeBUS.Get_Employee_By_ID(emp_ID);
                if (emp!= null)
                {
                    Session["Emp_Type"] = emp.Type;
                    Session["Emp_ID"] = emp.UserName;

                    if (emp.Type == 1)
                    {
                        Session["role"] = Define.ROLE_ADMIN;
                        Response.Redirect("../Admin/ManageSchedule.aspx");
                    }
                        
                    else
                        if (emp.Type == 2)
                        {
                            Session["role"] = Define.ROLE_EMPLOYEE;
                            Response.Redirect("../Admin/Schedule.aspx");
                        }
                            
                        else
                            if (emp.Type == 3)
                                Session["role"] = Define.ROLE_MANAGER;
                    Response.Redirect("../Admin/ScheduleToday.aspx");
                }
            }
        }


    }
}
